package cn.felord.app.base;

import cn.felord.app.security.SecureUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 基础controller
 *
 * @author Dax
 * @since 17 :34  2019-04-09
 */
public class BaseController {


    private SecureUser currentUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return (SecureUser) authentication.getPrincipal();
    }

    /**
     * 获取当前用户id.
     *
     * @return the string
     */
    public String currentUserId() {
        return currentUser().getUserId();
    }


    /**
     * 获取当前用户名.
     *
     * @return the string
     */
    public String currentUserName() {
        return currentUser().getUsername();
    }
}
